﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Imaging;

namespace WGCSFramework.images
{
    public class WgImages
    {
        /// <summary>
        /// Returns array string with names of the system encoders
        /// </summary>
        /// <returns>Names of the system encoders</returns>
        public static string[] getCodecNames()
        {
            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
            string[] arr = new string[codecs.Length];
            for (int i = 0; i < codecs.Length; i++) arr[i] = codecs[i].MimeType;
            return arr;
        }

        /// <summary>
        /// Returns array string with file extensions of the system encoders
        /// </summary>
        /// <returns>Names of the system encoders</returns>
        public static string[] getCodecExtensions()
        {
            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
            string[] arr = new string[codecs.Length];
            for (int i = 0; i < codecs.Length; i++) arr[i] = codecs[i].FilenameExtension;
            return arr;
        }

        /// <summary>
        /// Returns description for codec
        /// </summary>
        /// <param name="key">key value of the codec in array</param>
        /// <returns>Description of the codec</returns>
        public static string getCodecDescription(int key)
        {
            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
            return codecs[key].FormatDescription;
        }

        /// <summary>
        /// Return encoder info for myme type
        /// </summary>
        /// <param name="mimeType">mime type</param>
        /// <returns>Encoder info</returns>
        public static ImageCodecInfo GetEncoderInfo(string mimeType)
        {
            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
            for (int i = 0; i < codecs.Length; i++) if (codecs[i].MimeType == mimeType) return codecs[i];
            throw new Exception("No codec for " + mimeType);
        }
    }
}
